<?php

namespace App\Console\Commands;

use App\Models\OrderAppoint;
use App\Models\User;
use App\Models\Users\MoneyLog;
use Carbon\Carbon;
use Illuminate\Console\Command;

class Order extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Order:deal';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $date=Carbon::now()->subMinutes(5)->toDateTimeString();
        $list = OrderAppoint::where(['status'=>2])->whereDate('updated_at','<',$date)->get();
        foreach ($list as $order){
            $order->status=4;
            $order->save();
            User::query()->find($order->appoint_id)->increment('order_num');
            (new MoneyLog())->add($order->appoint_id, $order->total_price, '咨询收入', 3, $order->id);
        }
        return Command::SUCCESS;
    }
}
